package com.lucenten.collect.gnss.handler.files;

import com.lucenten.collect.gnss.entity.TecpTecl;
import com.lucenten.collect.gnss.entity.trans.TecpTeclTrans;
import com.lucenten.collect.gnss.handler.tools.GnssContext;
import com.lucenten.collect.gnss.handler.tools.compute.FactorialCalculator;
import com.lucenten.mq.SendJmsInfo;

public class CAzimuthElevation extends AzimuthElevation {
    /**
     * 计算仰角 方位角
     */
    public static void compute(TecpTeclTrans tecpTeclTrans, Double[] singlePath, TecpTecl tecpTecl, int startNum) {
        if (singlePath == null) {
            return;
        }
        NTools nTools = new NTools();
        double[] xyz = nTools.before(tecpTeclTrans, singlePath, tecpTecl);
        // 当卫星号在1~5内时，代表此卫星是北斗静止轨道卫星需要进行特殊处理，否则和N文件处理方式一样
        if (startNum <= 5) {
            xyz = min(singlePath, nTools);
        }
        nTools.after(tecpTeclTrans, tecpTecl, xyz);
//        SendJmsInfo.sendGnssMq(14, "", 0);
    }

    private static double[] min(Double[] singlePath, NTools nTools) {
        double xk = nTools.getXk(), yk = nTools.getYk(), ik = nTools.getIk(), tk = nTools.getTk();
        //静止轨道卫星c1~c5处理
        double geowgs_omegak = singlePath[13] + singlePath[18] * tk - GnssContext.WO * singlePath[11];
        double geowgs_xk01 = xk * Math.cos(geowgs_omegak) - yk * Math.cos(ik) * Math.sin(geowgs_omegak);
        double geowgs_yk01 = xk * Math.sin(geowgs_omegak) + yk * Math.cos(ik) * Math.cos(geowgs_omegak);
        double geowgs_zk01 = yk * Math.sin(ik);
        double xphi = (-5) * Math.PI / 180;
        double zphi = GnssContext.WO * tk;
        //矩阵运算
        FactorialCalculator calculator = new FactorialCalculator();
        double[][] Rx = {{1, 0, 0}, {0, Math.cos(xphi), Math.sin(xphi)}, {0, -Math.sin(xphi), Math.cos(xphi)}};
        double[][] Rz = {{Math.cos(zphi), Math.sin(zphi), 0}, {-Math.sin(zphi), Math.cos(zphi), 0}, {0, 0, 1}};
        double[][] Rz01 = {{geowgs_xk01, 0, 0}, {geowgs_yk01, 0, 0}, {geowgs_zk01, 0, 0}};
        double[][] vals = calculator.multiply(Rx, Rz);
        vals = calculator.multiply(vals, Rz01);
        return new double[]{vals[0][0], vals[1][0], vals[2][0]};
    }
}
